package com.example.myapplication.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.myapplication.R;
import com.example.myapplication.ui.adapter.RecordPagerAdapter;
import com.example.myapplication.ui.fragment.InComeFragment;
import com.example.myapplication.ui.fragment.OutComeFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class RecordActivity extends AppCompatActivity {

    private ImageView recordIvBack;
    private TabLayout recordTabs;
    private ViewPager recordVp;
    RecordPagerAdapter pagerAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_record);
        initView();
        initPager();
    }


    /**
     * 初始化控件
     */
    private void initView() {
        recordIvBack = (ImageView) findViewById(R.id.record_iv_back);
        recordTabs = (TabLayout) findViewById(R.id.record_tabs);
        recordVp = (ViewPager) findViewById(R.id.record_vp);
    }

    /**
     * 设置ViewPager加载页面
     */
    private  void  initPager(){
        //初始化ViewPager页面的集合
        List<Fragment>fragmentList=new ArrayList<>();
        //创建收入和支出页面,放置在Fragment当中
        OutComeFragment outComeFragment = new OutComeFragment();
        InComeFragment inComeFragment = new InComeFragment();
        fragmentList.add(outComeFragment);
        fragmentList.add(inComeFragment);
        //创建适配器
        pagerAdapter=new RecordPagerAdapter(getSupportFragmentManager(),fragmentList);
        //设置适配器对象
        recordVp.setAdapter(pagerAdapter);
        //将TabLayout和ViewPager进行关联
        recordTabs.setupWithViewPager(recordVp);
    }

    /**
     * 点击事件
     *
     * @param view
     */
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.record_iv_back:finish();
                break;
        }
    }
}